package com.wenzi.rule.verification.resolver;

import com.wenzi.rule.verification.spel.Rule;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.expression.AccessException;
import org.springframework.expression.BeanResolver;
import org.springframework.expression.EvaluationContext;
import org.springframework.stereotype.Component;

@Component
public class RuleBeanResolver implements BeanResolver,ApplicationContextAware {

    private ApplicationContext applicationContext;

    @Override
    public Object resolve(EvaluationContext context, String beanName) throws AccessException {
        Rule rule = (Rule) applicationContext.getBean(beanName);
        if(rule != null){
            rule.doRule(context);
        }else{

        }
        return null;
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        this.applicationContext = applicationContext;
    }
}
